<template>
  <div class="detail-title-wrapper" :class="{'hide-shadow': ifHideShadow}">
    <div class="title-left-wrapper" @click="back">
      <span class="iconfont icon-back">&#xe744;</span>
    </div>
    <div class="title-right-wrapper">
      <span class="iconfont icon" v-if="showShelf" @click="showBookShelf">&#xe609;</span>
      <span class="iconfont" v-else>&#xe608;</span>
    </div>
    <div class="title-text" v-if="title">
      {{title}}
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'DetailTitle',
  props: {
    title: String,
    showShelf: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      ifHideShadow: true
    }
  },
  methods: {
    showBookShelf () {
      this.$router.push('/store/shelf')
    },
    showShadow () {
      this.ifHideShadow = false
    },
    hideShadow () {
      this.ifHideShadow = true
    },
    back () {
      this.$emit('back')
    }
  }
}
</script>

<style lang="stylus" scoped>
@import "../../assets/styles/global"
.detail-title-wrapper
  position: relative
  display: flex
  width: 100%
  height: px2rem(42)
  box-shadow: 0 px2rem(2) px2rem(2) 0 rgba(0, 0, 0, .1)
  font-size: px2rem(20)
  color: #666
  &.hide-shadow
    box-shadow: none
  .title-left-wrapper
    position: relative
    z-index: 200
    flex: 1
    margin-left: px2rem(15)
    leftStyle()
    .icon-back
      font-size: px2rem(22)
  .title-right-wrapper
    position: relative
    z-index: 200
    flex: 1
    margin-right: px2rem(15)
    rightStyle()
  .title-text
    position: absolute
    top: 0
    left: 0
    z-index: 100
    width: 100%
    height: px2rem(42)
    font-size: px2rem(16)
    color: #333
    center()
</style>
